package com.qianfeng.xinyihezi.xinyihezi.jsondecode;

import android.util.Log;

import com.qianfeng.xinyihezi.xinyihezi.model.LabelList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tcoy on 2016/11/14.
 */

public class DecodeDataTag {
    private String TAG = getClass().getSimpleName();
    private List<LabelList> labelLists;

    public List<LabelList> getTagData(String json) {
        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONArray jsonArr = jsonObject.optJSONArray("data");
            JSONObject jsonObjectData = (JSONObject) jsonArr.get(0);
            JSONArray jsonArrayLabelList = jsonObjectData.optJSONArray("label_list");
            labelLists = new ArrayList<>();
            for (int i = 0; i < jsonArrayLabelList.length(); i++) {
                JSONObject jsonData = (JSONObject) jsonArrayLabelList.get(i);
                LabelList labelList = new LabelList(jsonData.optString("image_url"), jsonData.optString("label_id"), jsonData.optString("name"));
                labelLists.add(labelList);
            }
            return labelLists;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
